package org.foj.model {

import mx.collections.ArrayCollection;

public class GraphModel {
    public function GraphModel() {
    }

    public function groupCollectionBy(allIssues:ArrayCollection,
                                      field:String):ArrayCollection {
        var group:Array = new Array();

        for each(var issue:Object in allIssues) {
            if (group[issue[field]] == null) {
                group[issue[field]] = 1;
            } else {
                group[issue[field]]++;
            }
        }

        var result:ArrayCollection = new ArrayCollection();
        for (var key:String in group) {
            result.addItem({label: key, units: group[key]});
        }

        return result;
    }
}
}